class GroupAccountsController < AccountController #ActionController::Base  
  self.prepend_view_path Mephisto::Plugin.view_paths[:group_account]
  unloadable #http://dev.rubyonrails.org/ticket/6001
  layout "application"
  
  def index
    @users = site.users(:order => 'updated_at desc')
    @events, @todays_events, @yesterdays_events = [], [], []
    today, yesterday = utc_to_local(Time.now.utc).to_date, utc_to_local(1.day.ago.utc).to_date
    @articles = @site.unapproved_comments.count :all, :group => :article, :order => '1 desc', :conditions => ["user_id = ?", current_user]
    @site.events.find(:all, :order => 'events.created_at DESC', 
                      :include => [:article, :user],
                      :conditions => ["user_id = ?", current_user], :limit => 50).each do |event|
      event_date = utc_to_local(event.created_at).to_date
      if event_date >= today
        @todays_events
      elsif event_date == yesterday
        @yesterdays_events
      else
        @events
      end << event
    end
  end

  def new
    @user = User.new
    #render :action => "new", :layout => "simple"
  end

  def create
    @user = User.new params[:user]
    @user.filter = "Plain HTML"
    self.current_user if @user.save!
    @user.sites << site
    @user.section = Section.new params[:section]
    @user.section.path = @user.login
    @user.section.site = site
    @user.section.save!
    flash[:notice] = "User created."
    redirect_to :action => 'index'
  rescue ActiveRecord::RecordInvalid
    flash[:error] = "Save failed."
    render :action => 'new'
  end

end